package com.group.controller;

import com.group.utils.JwtUtils;
import com.group.utils.R;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @author: 如寄
 * @version: v1.0
 * @description: com.group.controller
 * @date:2021/9/11
 */
@ResponseBody
@RestController
@RequestMapping("/user")
@CrossOrigin
public class LoginController {

    @PostMapping("/login")
    public R login() {
        String token = JwtUtils.getJwtToken("1", "admin");
        return R.ok().data("token", token);
    }

    @GetMapping("info")
    public R info(HttpServletRequest request) {
        String memberId = JwtUtils.getMemberIdByJwtToken(request);
        return R.ok().data("roles", "lzx").data("name", "lzx").data("avatar", "https://pic.qqtn.com/up/2018-8/15350754659292448.gif");
    }

    @PostMapping("logout")
    public R logout() {
        return R.ok();
    }
}
